#include <linux/module.h>
#include <linux/slab.h>
#include <linux/init.h>

static int __init my_init(void)
{
	static char *kbuf;
	static unsigned long order;
	int size;

	pr_info("get MAX_ORDER %d", MAX_ORDER);

	for (size = PAGE_SIZE, order = 0; order <= MAX_ORDER;
	     order++, size *= 2) {
		pr_info("order %2ld, pages = %5ld, size = %#x", order,
			size / PAGE_SIZE, size);
		kbuf = (char *)__get_free_pages(GFP_ATOMIC, order);
		if (!kbuf)    {
			pr_err("get free error\r\n");
			break;
		}

		pr_info("get free ok\r\n");
		free_pages((unsigned long)kbuf, order);
	}

	for (size = PAGE_SIZE, order = 0; order <= MAX_ORDER;
	     order++, size *= 2) {
		pr_info("GFP_ATOMIC order %2ld, pages = %5ld, size = %d MB",
			order, size / PAGE_SIZE, size >> 20);
		kbuf = (char *)kmalloc(GFP_ATOMIC, order);
		if (!kbuf) {
			pr_err("kmalloc   error\r\n");
			break;
		}

		pr_info("kmalloc ok\r\n");
		kfree(kbuf);
	}

	for (size = PAGE_SIZE, order = 0; order <= MAX_ORDER;
	     order++, size *= 2) {
		pr_info("GFP_KERNEL order %2ld, pages = %5ld, size = %d MB",
			order, size / PAGE_SIZE, size >> 20);
		kbuf = (char *)kzalloc_node(GFP_KERNEL, order, 0);
		if (!kbuf) {
			pr_err("kzalloc_node   error\r\n");
			break;
		}

		pr_info("kzalloc_node ok\r\n");
		kfree(kbuf);
	}

	return 0;
}

static void __exit my_exit(void)
{
}

module_init(my_init);
module_exit(my_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Module named phypfn.");
